package gaml.testing;

import static org.junit.Assert.assertEquals;
import gaml.error.GamlException;
import gaml.java.serializer.EnumSerializer;
import gaml.yaml.ScalarNode;
import gaml.yaml.ahchor.YamlAnchorCodeStore;
import gaml.yaml.ahchor.YamlAnchorObjectStore;

import org.junit.Test;


public class EnumSerializerTest {
	
	enum Foo {
		VAL1 ("val1"),
		VAL2 ("val2"),
		VAL3 ("val3");
		
		String fooname;
		
		Foo (String fooname) { this.fooname = fooname; }
		
		public String getFooName () { return fooname; } 
	}

	@Test
	public void testSerialize () throws GamlException {
		EnumSerializer <Foo> s = new EnumSerializer <Foo> (Foo.class);
		assertEquals ("1, VAL2", s.serialize (s.createNode (null), Foo.VAL2, new YamlAnchorObjectStore ()).getValue ());
	}

	@Test
	public void testRestore () throws GamlException {
		EnumSerializer <Foo> s = new EnumSerializer <Foo> (Foo.class);
		assertEquals (Foo.VAL3, s.restore (new ScalarNode (null).setValue ("2, VAL3"), null, new YamlAnchorCodeStore ()));
	}

}
